from pathlib import Path

d1 = Path(input('请输入目录：'))
# d1 = Path(r'F:\手机备份\Pictures\一点资讯')
cat = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'mp4', 'ts', 'mp3', 'amr', 'avi', 'wmv', 'mkv', 'flv', 'rmvb', 'rm',
       'mov',
       'm4v',
       'm4a']

count = 0
for x in d1.glob('*.*'):
    ext = x.suffix.lower()[1:]
    if ext in cat:
        try:
            (d1 / ext).mkdir(exist_ok=True)
            x.replace(d1 / ext / x.name)
            count += 1
            print(count)
        except Exception as e:
            print(e)
